<?php

namespace app\common\model\acct;

use app\common\model\Acctmoneylog;
use think\Model;


class Withdrawal extends Model
{





    // 表名
    protected $name = 'acct_withdrawal';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'state_text'
    ];


    protected static function init()
    {
        self::beforeUpdate(function ($row) {
            $changed = $row->getChangedData();
            if (isset($changed['state']) && $changed['state'] == '3') {
                Acctmoneylog::money($row['money'], $row['user_id'], '提现失败返回', $row['sn']);
            }
        });
    }
    public function getStateList()
    {
        return ['1' => __('State 1'), '2' => __('State 2'), '3' => __('State 3')];
    }


    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function admin()
    {
        return $this->belongsTo('app\common\model\Admin', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
